<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>用户列表</title>
    <meta name="description" content="">
    <meta name="author" content="templatemo">
    <link href="../css/font-awesome.min.css" rel="stylesheet">
    <link href="../css/bootstrap.min.css" rel="stylesheet">
    <link href="../css/templatemo-style.css" rel="stylesheet">
    <link href="../css/admin.css" rel="stylesheet">
    <script src="http://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script>
    <script src="../js/admin.js"></script>
</head>

<body>
    <script>
        function deluser(id){
      if(window.confirm('确定删除吗？')){
          $.ajax({
                type: "GET",
                url: 'dodelUser.php',
                async: false,
                dataType: "json",
                data: {
                    'uid':id
                },
                success: function (msg) {
                    if (msg.status == 1) {
                        alert(msg.mes);
                        window.location.reload();
                    }
                    if (msg.status == -1) {
                        alert(msg.mes);
                        window.location.reload();
                    }
                },
                error: function (result) {
                    alert('请求失败!');
                }
            });
      }
    }
  </script>

    <?php
    require_once "../congfig/config.php";
    require_once "../lib/common.php";
    session_start();
    checkAdmin();
    $pagesize = 10;
    $page = empty($_GET['page']) ? 1 : $_GET['page'];
    $prepage = $page - 1;
    $nextpage = $page + 1;
    $sql = "select * from users  ";
    $query = $GLOBALS['conn']->query($sql);
    $num = $query->num_rows;
    $tatolpage = ceil($num / $pagesize);
    $startpage = ($page - 1) * $pagesize;
    @$key = $_GET['key'];
    if (isset($key)) {
      $sql = "select * from users where username like '%$key%'";
      $query = $GLOBALS['conn']->query($sql);
    } else {
      $sql = "select * from users  LIMIT $startpage,$pagesize ";
      $query = $GLOBALS['conn']->query($sql);
      // $result=$query1->fetch_array();
      // echo $result['pName'];
    }
    // $sql = "select * from users  LIMIT $startpage,$pagesize ";
    // $query = $GLOBALS['conn']->query($sql);
    // $num = $query->num_rows;

    ?>
    <!-- Left column -->
    <div class="templatemo-flex-row">
        <div class="templatemo-sidebar">
            <header class="templatemo-site-header">
                <div class="square"></div>
                <h1>后台管理系统</h1>
            </header>
            <div class="profile-photo-container">
                <img src="../images/profile-photo.jpg" alt="Profile Photo" class="img-responsive">
            </div>
            <!-- Search box -->

            <div class="mobile-menu-icon">
                <i class="fa fa-bars"></i>
            </div>
            <nav class="templatemo-left-nav">
                <ul>
                    <li id="xmgl"><a href="project-list.php"><i class="fa fa-bars fa-fw"></i>项目管理</a>
                        <ul>
                            <li><a href="addProject.php"><i class="fa fa-bars fa-fw"></i>添加项目</a></li>
                        </ul>
                        <ul>
                            <li><a href="applyproject.php"><i class="fa fa-bars fa-fw"></i>申请立项</a></li>
                        </ul>
                        <ul>
                            <li><a href="projectsucc.php"><i class="fa fa-bars fa-fw"></i>立项成功</a></li>
                        </ul>
                        <ul>
                            <li><a href="projectfail.php"><i class="fa fa-bars fa-fw"></i>立项失败</a></li>
                        </ul>
                        <ul>
                            <li><a href="applyprojectover.php"><i class="fa fa-bars fa-fw"></i>申请结项</a></li>
                        </ul>
                        <ul>
                            <li><a href="projectok.php"><i class="fa fa-bars fa-fw"></i>结项成功</a></li>
                        </ul>
                        <ul>
                            <li><a href="projectnok.php"><i class="fa fa-bars fa-fw"></i>结项失败</a></li>
                        </ul>
                        <ul>
                            <li><a href="goodpro.php"><i class="fa fa-bars fa-fw"></i>优秀项目</a></li>
                        </ul>
                    </li>
                    <li id="yhgl"><a href="#" class="active"><i class="fa fa-user fa-fw"></i>用户管理</a>
                        <ul>
                            <li><a href="addUser.php"><i class="fa fa-user fa-fw"></i>添加用户</a></li>
                        </ul>
                    </li>
                    <li><a href="pad-check.php"><i class="fa fa-cog fa-fw"></i>修改密码</a></li>
                    <li><a href="../loginout.php" id="zx"><i class="fa fa-map-marker fa-fw"></i>注销</a></li>
                </ul>
            </nav>
        </div>


        <div class="templatemo-content col-1 light-gray-bg" style="height:1000px;">
            <div class="container" style="margin-top:100px;">
                <div role="tabpanel" class="tab-pane" id="user">
                    <div class="check-div form-inline">
                        <form action="#" method="GET">
                            <div class="col-xs-4">
                                <input type="text" class="form-control input-sm" name="key" placeholder="输入文字搜索">
                                <button type="submit" class="btn btn-white btn-xs ">查 询 </button>
                            </div>
                        </form>
                    </div>
                    <div class="data-div">
                        <table class="table table-hover table-striped ">
                            <thead>
                                <tr>
                                    <th>编号</th>
                                    <th>学号/工号</th>
                                    <th>邮箱</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                while ($result = $query->fetch_array()) {
                                  ?>
                                <tr>
                                    <td id="user-id">
                                        <?php echo $result["uid"]; ?>
                                    </td>
                                    <td>
                                        <?php echo $result["username"]; ?>
                                    </td>
                                    <td>
                                        <?php echo $result["email"]; ?>
                                    </td>
                                    <td>
                                        <a class="btn btn-success btn-xs" href="alterUser.php?uid=<?php echo $result['uid'] ?>">修改</a>
                                        <button class="btn btn-danger btn-xs" onclick="deluser(<?php echo $result['uid']; ?>)">删除</button>
                                    </td>
                                </tr>
                                <?php

                              }
                              ?>
                    </div>
                    <?php
                    if ($prepage <= 0) {
                      $prepage = 1;
                    }
                    if ($nextpage > $tatolpage) {
                      $nextpage = $page;
                    }
                    ?>

                    </tbody>
                    </table>
                </div>
                <?php
                if ($prepage < 0) {
                  $prepage = 0;
                }
                if ($nextpage > $tatolpage) {
                  $nextpage = $page;
                }
                ?>
                <footer class="footer pull-right">
                    <ul class="pagination">
                        <li><a href="user-list.php?page=0"><i class=" fa fa-fast-backward" style="color:rgb(19,137,95);font-size:20px;"></i></a></li>
                        <li><a href="user-list.php?page=<?php echo $prepage ?>"><i class="fa fa-backward " style="color:rgb(19,137,95);font-size:20px;  "></i></a></li>
                        <li class="gray">
                            <span style="font-size:15px; height: 45px;padding-top:13px;">第
                                <?php echo $page ?> 页</span>
                        </li>
                        <li><a href="user-list.php?page=<?php echo $nextpage ?>"><i class="  fa fa-forward" style="color:rgb(19,137,95);font-size:20px;"></i></a></li>
                        <li><a href="user-list.php?page=<?php echo $tatolpage ?>"><i class=" fa fa-fast-forward" style="color:rgb(19,137,95);font-size:20px; "></i></a></li>
                    </ul>
                </footer>
            </div>
        </div>
    </div>
    </div>
</body>

</html> 